package com.common.supply.config.exception;

import com.common.supply.Utils.Func;
import com.common.supply.common.RspEnmu;
import com.common.supply.domain.AjaxResult;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * @author cyh
 * @date 2022/5/9 11:16 上午
 */
@RestControllerAdvice
public class GlobalExceptionHandler {

    private static final Logger log = LoggerFactory.getLogger(GlobalExceptionHandler.class);

    @ExceptionHandler(Exception.class)
    public AjaxResult handleException(Exception e) {
        log.error(e.getMessage(), e);
        return AjaxResult.error(RspEnmu.SYSTEM_BUSY.getRetMsg());
    }

    /**
     * 通用自定义异常
     */
    @ExceptionHandler(BusinessException.class)
    public AjaxResult handlerBusinessException(BusinessException e) {
        if (Func.isEmpty(e.getCode())) {
            return AjaxResult.error(e.getMessage());
        }
        return AjaxResult.error(e.getCode(), e.getMessage());
    }





}
